RFC: use AbstractMatrix
as the eltype of Symmetric
for array of arrays
#32041
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a crash in the StaticArrays tests on 1.2 and master. It can be reduced to this:
The functions
symmetric_type
andhermitian_type
are involved; they are both recursive and callreturn_type
and it seems we just cannot handle it. The eltype ofa
is currentlyUnion{Array{Complex{Int64},2}, Adjoint{Complex{Int64},Array{Complex{Int64},2}}, Hermitian{Complex{Int64},Array{Complex{Int64},2}}}
, which does not seem too useful to me. Here I switch it toAbstractMatrix
instead, which works around the problem.An alternate possible fix is to reduce the complexity of Symmetric and Hermitian
getindex
. They currently return three different types for diagonal, upper, and lower. I can also fix the crash by reducing this to two. My proposal is to materialize the recursive Symmetric/Hermitian array, removing the third type fromUnion{S, promote_op(transpose, S), symmetric_type(S)}
. That gives a bit more precise type info, but would be more breaking since it changes whatgetindex
returns, while this PR only changes the element type of the Symmetric/Hermitian wrapper.Any way we can avoid
promote_op
would be even better, and would also fix it. For example I'd usetypeof(transpose(a[1]))
, andUnion{}
for empty arrays. But that would break thesymmetric_type
API, which expects to be able to compute the eltype from just a type.